<?php
/*
YHM (Your Hosting Manager) - Copyright 2010 All Rights Reserved. - YHM Group
Released under the Simplified BSD Licence.

Website: http://yhm.co.uk
Licence: http://yhm.co.uk/about/#licence

file: includes/functions.php
author: Kieran D. (Polarbear541)
*/

function random_str($length)
{
	$chars="aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ1234567890";
	$len=strlen($chars);
	$i=1;

	while ($i <= $length)
	{
		$rand=rand(1,$len);
		$str.=$chars[$rand-1];
		$i++;
	}
	
	return $str; 
}

function checklogin_client()
{
	if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true)
	{
		// not logged in, throw guest to login page
		redirect("../member.php?action=login");
		exit();
	}
	elseif ($_SESSION['gid'] == "1")
	{
		redirect("../admin/");
		exit();
	}
}

function checklogin_admin()
{
	if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true)
	{
		// not logged in, throw guest to login page
		redirect("../member.php?action=login");
		exit();
	}
	elseif ($_SESSION['gid'] == "0")
	{
		redirect("../client/");
		exit();
	}
}

function error($message)
{
	echo "<div class='error'><p><em>Error: $message</em></p></div><br />";
}

function redirect($url, $seconds=0) 
{
	echo "<br /><meta http-equiv='refresh' content='$seconds; url=$url'>"; 
	return true;
}
?>